package sunset.lucifer.ko.service.impl;

import sunset.lucifer.ko.dao.UserDao;
import sunset.lucifer.ko.enums.MessageEnum;
import sunset.lucifer.ko.model.User;
import sunset.lucifer.ko.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2016/11/18.
 */
@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

    @Autowired
    private UserDao userDao;

    /**
     * 获取具体dao类
     */
    @Autowired
    public void setBaseDao() {
        super.setBaseDao(userDao);
    }

    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @Override
    public int insertRecord(User user) {
        if (userDao.getRecordByCondition(user).size() != 0) {
            System.out.println("NOOOOOOOOOOOOOOOOOOOOOOOOOO");
            System.out.println(userDao.getRecordByCondition(user).size());
            User userRecord = userDao.getRecordByCondition(user).get(0);
            //判断联系方式
            if (userRecord.getEmail() != null || !("".equals(userRecord.getEmail()))) {
                return MessageEnum.EMAIL_EXITED.getValue();
            }
            if (userRecord.getUsername() != null || !("".equals(userRecord.getUsername()))) {
                return MessageEnum.USER_EXITED.getValue();
            }
        }
        //添加数据
        System.out.println("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYS");
        Integer count = userDao.insertRecord(user);
        if (count > 0) {
            return MessageEnum.OPERATE_SUCCESS.getValue();
        }
        return MessageEnum.OPERATE_ERROR.getValue();
    }
}
